AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")

include("shared.lua")

function ENT:Initialize()
	self.Entity:SetModel("models/lk_models/lk_largeshell.mdl") 
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_NONE )  
	
	self.Entity:NextThink( CurTime() )
end

function LkDamage( ent, dmg )
	if(ent:IsPlayer()) then return end
	if( ent.hp==nil ) then
		ent.maxhp = GetHealth( ent )
		ent.hp = ent.maxhp - dmg
		if( ent.hp<=0 ) then ent:Remove() end
	else
		ent.hp = ent.hp - dmg
		if( ent.hp<=0 ) then ent:Remove() end
	end
end

function ENT:Think()

self.Vel = self.Vel - Vector(0,0,self.gravity)

local tr = {}
	tr.start = self.Entity:GetPos()
	tr.endpos = self.Entity:GetPos() + self.Vel
	tr.filter = self.Entity
	local trace = util.TraceLine( tr )
	self.Entity:SetPos(	trace.HitPos )
	self.Entity:SetAngles( trace.Normal:Angle() )
	
	if( trace.Hit or self.dietime<CurTime() ) then
		if(trace.Entity:IsValid() and !trace.Entity:IsWorld()) then
		ent = trace.Entity
		
		if( ent.core!=nil and ent.core:IsValid() ) then
			if( table.HasValue(ent.core.Ents,ent) ) then
				if( ent.core.ply:Team() != self.core.ply:Team() ) then
					ent.core.hp = ent.core.hp - self.damage
					if( ent.core.hp<=0 ) then 
						ent.core:DoDeath(self.core) 
					end
				end
			else
				ent.core = nil
				LkDamage( ent, self.damage )
			end
		else
			LkDamage( ent, self.damage )
		end
		end
		local effectdata = EffectData()
		effectdata:SetOrigin( self.Entity:GetPos() )
		effectdata:SetScale( self.ExpScale )
		util.Effect( "lk_explosion" , effectdata )
		self.Entity:EmitSound("bulletexplosion.wav",120,130)
		self.Entity:Remove()
	end

self.Entity:NextThink( CurTime() + 0.02 )
return true
end

